<?php


namespace App\Http\Controllers\admin\model;


use Illuminate\Support\Facades\DB;

class ParentSnModel
{
    public static function delete($where){
        return DB::table('t_parent_sn')->where($where)->delete();
    }

    public static function edit($where,$param){
        return DB::table('t_parent_sn')->where($where)->update($param);
    }

    public static function queryFirst($where,$field){
        return DB::table('t_parent_sn')->where($where)->first($field);
    }

    public static function queryLeftGet($where,$field){
        return DB::table('t_parent_sn as p')
            ->leftJoin('t_admin_sn as a','p.admin_sn_id','=','a.id')
            ->where($where)
            ->get($field);
    }

    public static function add($param){
        return DB::table('t_parent_sn')->insert($param);
    }

    public static function insertGetId($param){
        return DB::table('t_parent_sn')->insertGetId($param);
    }     

    public static function queryWhereFirst($where){
        return DB::table('t_parent_sn as t')
            ->leftJoin('t_admin_sn as a','t.admin_sn_id','=','a.id')
            ->where($where)
            ->first(['t.id','t.teacher_id','a.value']);
    }

    public static function queryCount($where=[],$param=[]){
        if(isset($param['type']) && $param['type']!=1){
            return DB::table('t_parent_sn as tp')
                ->leftJoin('t_admin_sn as as','tp.admin_sn_id','=','as.id')
                ->leftJoin('t_admin as a','tp.admin_id','=','a.id')
                ->where($where)
                ->where("$param[field]",'like','%'.$param["$param[field]"].'%')
                ->count('tp.id');
        }
        return DB::table('t_parent_sn as tp')
            ->leftJoin('t_admin_sn as as','tp.admin_sn_id','=','as.id')
            ->leftJoin('t_admin as a','tp.admin_id','=','a.id')
            ->where($where)
            ->count('tp.id');
    }

    public static function queryAll($where=[],$param=[],$page,$field){
        if(isset($param['type']) && $param['type']!=1){
            return DB::table('t_parent_sn as tp')
                ->leftJoin('t_admin_sn as as','tp.admin_sn_id','=','as.id')
                ->leftJoin('t_admin as a','tp.admin_id','=','a.id')
                ->where($where)
                ->where("$param[field]",'like','%'.$param["$param[field]"].'%')
                ->offset($page['startSize'])
                ->limit($page['pageSize'])
                ->get($field);
        }
        return DB::table('t_parent_sn as tp')
            ->leftJoin('t_admin_sn as as','tp.admin_sn_id','=','as.id')
            ->leftJoin('t_admin as a','tp.admin_id','=','a.id')
            ->where($where)
            ->offset($page['startSize'])
            ->limit($page['pageSize'])
            ->get($field);
    }

    public static function queryGet($where,$field){
        return DB::table('t_parent_sn')->where($where)->distinct('admin_id')->get($field);
    }

    public static function queryWhere($where,$field){
        return DB::table('t_parent_sn')
            ->leftJoin('t_admin_sn as a','t_parent_sn.admin_sn_id','=','a.id')
            ->where($where)
            ->get($field);
    }

    
}